//package com.sinothk.special.im.service.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.sinothk.base.version.domain.vo.SearchCommVO;
//import com.sinothk.special.im.entity.MessageAll;
//import com.sinothk.special.im.entity.MsgLatest;
//import com.sinothk.special.im.entity.MsgLatestVO;
//import com.sinothk.special.im.mapper.MessageAllMapper;
//import com.sinothk.special.im.mapper.MsgLatestMapper;
//import com.sinothk.special.im.service.IMsgLatestService;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.shiro.SecurityUtils;
//import org.jeecg.common.system.vo.LoginUser;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
///**
// * @Description: 消息中心-最新消息
// * @Author: Liangyt
// * @Date: 2022-01-24
// * @Version: V1.0
// */
//@Service
//public class MsgLatestServiceImpl extends ServiceImpl<MsgLatestMapper, MsgLatest> implements IMsgLatestService {
//
//    @Resource
//    private MessageAllMapper messageAllMapper;
//
//    @Override
//    public IPage<MsgLatest> listForLoginUser(SearchCommVO searchVo, Integer pageNo, Integer pageSize) {
//        LambdaQueryWrapper<MsgLatest> queryWrapper = new LambdaQueryWrapper<>(); // todo
//        if (StringUtils.isNotEmpty(searchVo.getKeywords())) {
//            queryWrapper.like(MsgLatest::getMsgContent, searchVo.getKeywords());
//        }
//        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        queryWrapper.eq(MsgLatest::getReceiveUserId, loginUser.getId());
//        queryWrapper.orderByDesc(MsgLatest::getCreateTime);
//        return this.page(new Page<>(pageNo, pageSize), queryWrapper);
//    }
//
//    @Override
//    public void saveData(MsgLatestVO vo) {
//        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        // 新增最新消息
//        LambdaQueryWrapper<MsgLatest> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(MsgLatest::getReceiveUserId, vo.getReceiveUserId());
//        wrapper.eq(MsgLatest::getSendUserId, loginUser.getId());
//        this.remove(wrapper);
//
//        MsgLatest msgLatest = new MsgLatest();
//        BeanUtils.copyProperties(vo, msgLatest);
//        msgLatest.setMsgState(2);//消息状态0已创建1发送中2已接收3接收失败5已读
//        // 发送人
//        msgLatest.setSendUserId(loginUser.getId());
//        msgLatest.setSendUserName(loginUser.getRealname());
//        msgLatest.setSendUserAvatar(loginUser.getAvatar());
////        // 接收人
////        SysUser sysUser = sysUserService.getById(vo.getReceiveUserId());
////        msgLatest.setReceiveUserId(sysUser.getId());
////        msgLatest.setReceiveUserName(sysUser.getRealname());
////        msgLatest.setReceiveUserAvatar(sysUser.getAvatar());
//        this.save(msgLatest);
//
//        // 加入到所有消息
//        MessageAll messageAll = new MessageAll();
//        BeanUtils.copyProperties(msgLatest, messageAll);
//        messageAllMapper.insert(messageAll);
//    }
//}
